/********************************************************************************
 * RSSFeedGenerator.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Jan 9, 2009 10:29:27 AM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/
package com.printeverywhere.util;

import java.util.List;

import viecili.jrss.generator.RSSFeedGeneratorFactory;
import viecili.jrss.generator.elem.Channel;
import viecili.jrss.generator.elem.Item;
import viecili.jrss.generator.elem.RSS;
import viecili.jrss.generator.elem.Channel.Category;

import com.printeverywhere.dto.ItemCategories;


public class RSSFeedGenerator {
	public static String getContent(List<ItemCategories> itemsList, String language, String coName, String link, int catId) {
		viecili.jrss.generator.RSSFeedGenerator rssFeedGenerator = RSSFeedGeneratorFactory.getDefault();
		RSS rss = new RSS();
		rss.setVersion("2.0");

		try {
			Channel channel = new Channel(coName, link + "?lang=en&catId=" + catId, "Sample description");
			Category category = channel.new Category("Sample Category");

			channel.addCategory(category);
			channel.setPubDate(DateUtil.getTodaysDate());
			channel.setLastBuildDate(DateUtil.getTodaysDate());
			channel.setLanguage(language);
			channel.setCopyright("");

			int totalItems = itemsList.size();
			for (int index = 0; index < totalItems; index++) {
				ItemCategories pppItem = itemsList.get(index);
				Item item = new Item(pppItem.getItemId().getTitle(), pppItem.getItemId().getDescription());
				item.addCategory(item.new Category(pppItem.getCategoryId().getCategoryName()));
				item.setLink(link + "../../../showItem.htm?cid=" + pppItem.getItemId().getItemId());
				item.setAuthor(pppItem.getItemId().getUserId().getUserId());
				channel.addItem(item);
			}

			rss.addChannel(channel);
			return rssFeedGenerator.generateAsString(rss);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}
}
